package com.itcast.cn.response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 相应字符数据
 *
 */
@WebServlet("/responseDemo3")
public class ResponseDemo3 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码格式,放在最前面
        response.setContentType("text/html;charset=utf-8");
        //request.setCharacterEncoding("UTF-8");

        //1.获取字符输出流
        PrintWriter writer = response.getWriter();
        //content-type告诉浏览器解析的时候，用html方式解析就行。不要用纯文本
        //response.setHeader("content-type","text/html");

        writer.write("aaa");
        writer.write("<h1> 你好 </h1>");

        //不需要手动的关闭流
        //writer.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
